import 'package:flutter/material.dart';

/// Integration测试
/// 1. 创建一个页面用于测试
/// 2. 添加flutter_driver依赖
/// 3. 创建测试文件
/// 4. 关联App--integrationApp.dart
/// 5. 编写测试文件
/// 6. 运行测试文件

class IntegrationApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final String appTitle = 'Counter App';
    return MaterialApp(
      title: appTitle,
      theme: ThemeData(primarySwatch: Colors.red),
      home: IntegrationAppPage(title: appTitle),
    );
  }
}

class IntegrationAppPage extends StatefulWidget {
  final String title;

  IntegrationAppPage({Key key, this.title}) : super(key: key);

  @override
  State<StatefulWidget> createState() => IntegrationAppPageState();
}

class IntegrationAppPageState extends State<IntegrationAppPage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            // 设置key, 用于测试
            Text(
              '$_counter',
              key: Key('counter'),
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        key: Key('increment'),
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
